package Demo10;

public class ArrayList {
    public static void main(String[] args) {

    java.util.ArrayList<Student> students = new java.util.ArrayList<>();


    students.add(new Student(1, "张三"));
    students.add(new Student(2, "李四"));
    students.add(new Student(3, "王五"));


    for (Student student : students) {
        System.out.println(student);
    }


    for (Student student : students) {
        if ("张三".equals(student.getName())) {
            student.setName("张三丰");
            break; // 假设只有一个叫张三的学生
        }
    }


    System.out.println("修改张三姓名后：");
    for (Student student : students) {
        System.out.println(student);
    }


    for (int i = 0; i < students.size(); i++) {
        if ("王五".equals(students.get(i).getName())) {
            students.remove(i);
            break; // 假设只有一个叫王五的学生
        }
    }


    System.out.println("删除王五后：");
    for (Student student : students) {
        System.out.println(student);
    }
}
}

